home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / vbxwzrd / backgrnd.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-02-20  |  5.4 KB  |  168 lines

  1. {
  2.   Program: BackGrnd
  3.   Date: 20/2/1995
  4.   Purpose: To create a custom control (vbx) for Visual Basic or Delphi
  5. }
  6. Library BackGrnd;
  7. {$R BackGrnd}
  8. Uses WinTypes,WinProcs,VBApi;
  9. { Custom control data and structs }
  10. Type PBackGrnd=^TBackGrnd;
  11.      TBackGrnd=Record
  12.       About:Enum;
  13.       Picture:hPic;
  14.      End;
  15. Const 
  16. { Declare Property }
  17.       Property_About:TPROPINFO=(
  18.       npszName:NPnt(PChar('(About)'));
  19.       fl:DT_ENUM or PF_fGetData or PF_fSetData or PF_fSetMsg;
  20.       offsetData:Byte(0);
  21.       infoData:0;
  22.       dataDefault:0;
  23.       npszEnumList:Npnt(PChar('Click on "..." for About Box'+#0+#0));
  24.       enumMax:0);
  25.       Property_Picture:TPROPINFO=(
  26.       npszName:NPnt(PChar('Picture'));
  27.       fl:DT_PICTURE or PF_fGetData or PF_fSaveData or PF_fSetData or PF_fSetMsg;
  28.       offsetData:Byte(1);
  29.       infoData:0;
  30.       dataDefault:0;
  31.       npszEnumList:Npnt(PChar(+#0+#0));
  32.       enumMax:0);
  33. { Declare Events }
  34.       Event_BeginPaint:TEVENTINFO=(
  35.       npszName:NPnt(PChar('BeginPaint'));
  36.       cParms:0;
  37.       cwParms:2*0;
  38.       npParmTypes:0;
  39.       npszParmProf:NPnt(PChar(''));
  40.       fl:0);
  41.       Event_EndPaint:TEVENTINFO=(
  42.       npszName:NPnt(PChar('EndPaint'));
  43.       cParms:0;
  44.       cwParms:2*0;
  45.       npParmTypes:0;
  46.       npszParmProf:NPnt(PChar(''));
  47.       fl:0);
  48. { Property List }
  49.       PropListBackGrnd:array[0..11] of PPropInfo=(
  50.       PPropInfo_Std_CTLNAME,
  51.       PPropInfo_Std_HWND,
  52.       PPropInfo_Std_INDEX,
  53.       PPropInfo(@Property_About),
  54.       PPropInfo_Std_ENABLED,
  55.       PPropInfo_Std_HEIGHT,
  56.       PPropInfo_Std_LEFT,
  57.       PPropInfo_Std_TOP,
  58.       PPropInfo_Std_VISIBLE,
  59.       PPropInfo_Std_WIDTH,
  60.       PPropInfo(@Property_Picture),0);
  61. { Event List }
  62.       EventListBackGrnd:array[0..7] of PEventInfo=(
  63.       PEventInfo(@Event_BeginPaint),
  64.       PEventInfo_Std_CLICK,
  65.       PEventInfo_Std_DBLCLICK,
  66.       PEventInfo(@Event_EndPaint),
  67.       PEventInfo_Std_MOUSEDOWN,
  68.       PEventInfo_Std_MOUSEMOVE,
  69.       PEventInfo_Std_MOUSEUP,0);
  70. { This routine handles the 'About' Dialog messages }
  71. function AboutDlgProc(Dlg:HWnd;Msg,wParam:Word;lParam:LongInt):Bool; export;
  72. begin
  73.   AboutDlgProc:=False;
  74.   case Msg of
  75.     WM_Create:AboutDlgProc:=True;
  76.     WM_InitDialog:Exit;
  77.     WM_Command:if (wParam=id_OK)or(wParam=id_Cancel) then EndDialog(Dlg,0);
  78.   end;{End of Case}
  79. end;
  80. { Constans and Variables }
  81. { Control Procedure }
  82. { This routine is called for all VB and Windows Messages }
  83. function BackGrndCtlProc(Control:hCtl;Wnd:hWnd;Msg,wParam:Word;lParam:LongInt):LongInt; Export;
  84. const hBrOld:hBrush=0;
  85. var TP:TPaintStruct;
  86.     Pic:Tpic;
  87.     hPicture:hPic;
  88.     BMP:TBitmap;
  89.     hBR:hBrush;
  90.     MemDC:hDC;
  91.     Rect:TRect;
  92.     X,Y:Integer;
  93. begin
  94.   case Msg of
  95.     WM_PAINT:
  96.     begin
  97.       if VBGetMode=MODE_RUN then VBFireEvent(Control,0,nil);
  98.       BeginPaint(Wnd,TP);
  99.       VBGetControlProperty(Control,10,@hPicture);
  100.       if hPicture<>0 then
  101.         begin
  102.           VBGetPic(hPicture,@Pic);
  103.           hBR:=GetBrushOrg(TP.hDC);
  104.           if Bool(hbr) then hbrOld:=SelectObject(TP.hDC,hBR);
  105.           GetClientRect(Wnd,Rect);
  106.           GetObject(Pic.PicData.Bitmap,sizeof(TBitMap),PChar(@Bmp));
  107.           MemDC:=CreateCompatibleDC(TP.hDC);
  108.           SelectObject(MemDC,Pic.PicData.Bitmap);
  109.           Y:=0;
  110.           while Y<Rect.Bottom do
  111.           begin
  112.             X:=0;
  113.             while X<Rect.Right do
  114.             begin
  115.               BitBlt(TP.hDC,X,Y,BMP.bmWidth,BMP.bmHeight,MemDC,0,0,SRCCOPY);
  116.               X:=X+BMP.bmWidth;
  117.             end;
  118.             Y:=Y+BMP.bmHeight;
  119.           end;
  120.           SelectObject(TP.hDC,hbrOld);
  121.           DeleteDC(MemDC);
  122.         end;
  123.       EndPaint(Wnd,TP);
  124.       if VBGetMode=MODE_RUN then VBFireEvent(Control,3,nil);
  125.       Exit;
  126.     end;
  127.     VBM_SETPROPERTY:if wParam=10 then InvalidateRect(Wnd,nil,True);
  128.     WM_USER:VBDialogBoxParam(hInstance,'ABOUT',@AboutDlgProc,0);WM_USER+1:VBDialogBoxParam(hInstance,'ABOUT',@AboutDlgProc,0);
  129.     VBM_INITPROPPOPUP:if wParam=3 then
  130.     begin
  131.       BackGrndCtlProc:=LoWord(lParam+1);
  132.       PostMessage(Wnd,WM_USER,0,0);
  133.       Exit;
  134.     end;
  135.   end;    { End of case Msg }
  136.   BackGrndCtlProc:=VBDefControlProc(Control,Wnd,Msg,wParam,lParam);
  137. end; {End of Control function}
  138. { Model struct                               }
  139. { Define the control model                   }
  140. { (using the event and property structures). }
  141. Const ModelBackGrnd:TModel=(
  142.       UsVersion:VB300_VERSION;    { VB version used by control }
  143.       Fl:0;
  144.       CtlProc:TFarProc(@BackGrndCtlProc);
  145.       FsClassStyle:0 or cs_HRedraw or cs_VRedraw;
  146.       FlWndStyle:0;
  147.       CbCtlExtra:SizeOf(TBackGrnd);
  148.       IdBmpPalette:8000;          { Bitmap ID for tool palette }
  149.       DefCtlName:NPnt(PChar('BackGrnd'));
  150.       ClassName:NPnt(PChar('BackGrnd'));
  151.       ParentClassName:0;
  152.       PropList:Ofs(PropListBackGrnd);
  153.       EventList:Ofs(EventListBackGrnd);
  154.       NDefProp:0;                 { Index of default property }
  155.       NDefEvent:0);               { Index of default event }
  156. { Register custom control.                     }
  157. { This routine is called by VB when the custom }
  158. { control DLL is loaded for use.               }
  159. function VBInitCC(usVersion:Word;fRunTime:Boolean):Boolean; Export;
  160. begin
  161.   VBInitCC:=VBRegisterModel(hInstance,ModelBackGrnd);
  162. end;
  163. Exports
  164.   VBInitCC         index 2,
  165.   BackGrndCtlProc index 3,
  166.   AboutDlgProc;
  167. Begin
  168. End. { End of Custom Control }